<?php
include('member_resume_controller.php');
class JobController extends MemberResumeController {
	var $name = 'Job';
	
	var $layout = 'admin';
	
	function index() {
		$this->rdCompany->id = 1;
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$company_id = $this->rdCompany->company_id;
		$news = $this->News->findAll(
			'"News"."deleted" is null and "News"."title" is not null', '', 
			'News.created desc', 10);
		$this->set('news', $news);
		
		$jobs = $this->Job->findAll(
			'"Job"."deleted" is null and "Job"."company_id"=' . $company_id, 
			null, 'Job.created desc', 5);
		foreach($jobs as &$job) {
			if (date('Y-m-d', time()) >= $job['Job']['public_start'] && date(
				'Y-m-d', time()) <= $job['Job']['public_end'] && $job['Job']['job_status_id'] == 1 && empty(
				$job['Job']['public_close_date'])) {
				$job['Job']['public_state'] = '掲載中';
			} elseif (($job['Job']['public_start'] > date('Y-m-d', time()) || empty(
				$job['Job']['public_start']) || empty($job['Job']['public_end'])) && $job['Job']['job_status_id'] == 1) {
				$job['Job']['public_state'] = '掲載待ち';
			} elseif ($job['Job']['job_status_id'] == 0) {
				$job['Job']['public_state'] = '承認待ち';
			} elseif ($job['Job']['job_status_id'] == 2) {
				$job['Job']['public_state'] = '保留・差し戻し';
			} elseif ($job['Job']['job_status_id'] == 1 && ($job['Job']['public_end'] < date(
				'Y-m-d', time()) || !empty($job['Job']['public_close_date']))) {
				$job['Job']['public_state'] = '掲載終了';
			}
			$order_count = $this->Order->findCount(
				'"Order"."job_id"=' . $job['Job']['id']);
			$job['Job']['order_count'] = $order_count;
		}
		
		$this->set('jobs', $jobs);
	}
	function job_add() {
		$this->rdCompany->id=1;
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		//echo $this->rdCompany->company_id;      //此处屏蔽该输出
		$company = $this->Company->find(
			'"Company"."id"=' . $this->rdCompany->company_id);
		$this->set('company', $company);
		$post_data = $this->SysParams->generateList(
			"\"SysParams\".\"kbn\" = 'post_id' and \"SysParams\".\"deleted\" is null");
		$this->set('post_data', $post_data);
		$lang_data = $this->SysParams->generateList(
			"\"SysParams\".\"kbn\" = 'hope_language_id' and \"SysParams\".\"deleted\" is null", 
			'sort');
		$this->set('lang_data', $lang_data);
		$memb_type = $this->SysParams->generateList(
			"\"SysParams\".\"kbn\" = 'hope_member_id' and \"SysParams\".\"deleted\" is null");
		$this->set('member_type', $memb_type);
		$attention_data = $this->SysParams->generateList(
			"\"SysParams\".\"kbn\" = 'attention_id' and \"SysParams\".\"deleted\" is null");
		$this->set('attention_data', $attention_data);
		if (empty($this->data)) {
			$this->render('job_add');
			exit();
		}
		$message = $this->Job->valid($this->Valid, $this->data);
		if ($this->data['Job']['agree_flg'] == 0) {
			$message .= $this->Valid->tagErrorMsg('agree');
		}
		if ($this->data['Job']['email3_flg'] == 1 && empty(
			$this->data['Job']['email3'])) {
			$message .= $this->Valid->TagErrorMsg('required', 'Job/email3');
		}
		if (!empty($this->data['Job']['hope_language'])) {
			foreach($this->data['Job']['hope_language'] as $index => $hope) {
				if ($this->data['Job']['hope_language'][$index] == 4 && empty(
					$this->data['Job']['hope_language_note'])) {
					$message .= $this->Valid->TagErrorMsg('required', 
						'Job/hope_language_note');
				}
			}
		}
		if ($message) {
			$this->set('message', $message);
			$this->render('job_add');
			exit();
		}
		
		//20101227 jiang 进行company id防止hack处理，使用session中的company id替换任何表单中的conmpany id
		$this->data['Job']['company_id'] = $this->rdCompany->company_id;
		
		$this->Session->write('job_info', $this->data);
		$this->redirect('job/job_add_confirm');
	}
	
	function agreement() {
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
	}
	
	function job_add_confirm() {
		$this->rdCompany->id=1;
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$job_info = $this->Session->read('job_info');
		$company = $this->Company->find(
			'"Company"."id"=' . $this->rdCompany->company_id);
		
		$job_info['Job']['email1'] = $company['Company']['email'];
		if ($job_info['Job']['email2_flg'] == 1) {
			$job_info['Job']['email2'] = $company['Company']['incept_email'];
		} else {
			$job_info['Job']['email2'] = null;
		}
		if ($job_info['Job']['email3_flg'] == 0) {
			$job_info['Job']['email3'] = null;
		}
		$this->set('company', $company);
		$this->set('job', $job_info);
		//		
		$sql = "SysParams.kbn='post_id' and SysParams.deleted is null and SysParams.id in (";
		foreach($job_info['Job']['post_type'] as $jarea) {
			$sql = $sql . $jarea . ",";
		}
		$sql = substr($sql, 0, strlen($sql) - 1) . ")";
		$arr = array();
		$paras = $this->SysParams->findAll($sql);
		for($i = 0; $i < count($paras); $i++) {
			$arr[$i] = $paras[$i]['SysParams']['name'];
		}
		$this->set('post_type', implode('，', $arr));
		//
		if (!empty($job_info['Job']['hope_member'])) {
			$sql = "SysParams.kbn='hope_member_id' and SysParams.deleted is null and SysParams.id in (";
			foreach($job_info['Job']['hope_member'] as $jarea) {
				$sql = $sql . $jarea . ",";
			}
			$sql = substr($sql, 0, strlen($sql) - 1) . ")";
			$arr = array();
			$paras = $this->SysParams->findAll($sql);
			for($i = 0; $i < count($paras); $i++) {
				$arr[$i] = $paras[$i]['SysParams']['name'];
			}
			$this->set('hope_members', implode('，', $arr));
		}
		//
		if (!empty($job_info['Job']['attention'])) {
			$sql = "SysParams.kbn='attention_id' and SysParams.deleted is null and SysParams.id in (";
			foreach($job_info['Job']['attention'] as $jarea) {
				$sql = $sql . $jarea . ",";
			}
			$sql = substr($sql, 0, strlen($sql) - 1) . ")";
			$arr = array();
			$paras = $this->SysParams->findAll($sql);
			for($i = 0; $i < count($paras); $i++) {
				$arr[$i] = $paras[$i]['SysParams']['name'];
			}
			$this->set('attentions', implode('，', $arr));
		}
		//
		if (!empty($job_info['Job']['hope_language'])) {
			$sql = "SysParams.kbn='hope_language_id' and SysParams.deleted is null and SysParams.id in (";
			foreach($job_info['Job']['hope_language'] as $jarea) {
				$sql = $sql . $jarea . ",";
			}
			$sql = substr($sql, 0, strlen($sql) - 1) . ")";
			$arr = array();
			$paras = $this->SysParams->findAll($sql);
			for($i = 0; $i < count($paras); $i++) {
				if ($paras[$i]['SysParams']['id'] != 4) {
					$arr[$i] = $paras[$i]['SysParams']['name'];
				} else {
					$arr[$i] = $job_info['Job']['hope_language_note'];
				}
			}
			$this->set('languages', implode('，', $arr));
		}
	}
	
	function job_add_save() {
		$this->rdCompany->id=1;
		ini_set('memory_limit', '1024M');
		
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$job_info = $this->Session->read('job_info');
		$company = $this->Company->find(
			'"Company"."id"=' . $this->rdCompany->company_id);
		
		$job_info['Job']['email1'] = $company['Company']['email'];
		if ($job_info['Job']['email2_flg'] == 1) {
			$job_info['Job']['email2'] = $company['Company']['incept_email'];
		}
		if ($job_info['Job']['email3_flg'] != 1) {
			$job_info['Job']['email3'] = null;
		}
		$job_info['Job']['admin_id'] = $this->rdCompany->id;
		if ($this->Job->save($job_info)) {
			$job_id = $this->Job->getLastInsertID();
			foreach($job_info['Job']['post_type'] as $post_type) {
				$this->JobPost->save(
					array(
						"job_id"=>$job_id, "post_id"=>$post_type 
					));
			}
			if (!empty($job_info['Job']['hope_member'])) {
				foreach($job_info['Job']['hope_member'] as $hope_member) {
					$this->JobHopeMember->save(
						array(
							"job_id"=>$job_id, 
							"hope_member_id"=>$hope_member 
						));
				}
			}
			if (!empty($job_info['Job']['hope_language'])) {
				foreach($job_info['Job']['hope_language'] as $hope_language) {
					$this->JobHopeLanguage->save(
						array(
							"job_id"=>$job_id, 
							"hope_language_id"=>$hope_language 
						));
				}
			}
			if (!empty($job_info['Job']['attention'])) {
				foreach($job_info['Job']['attention'] as $attention) {
					$this->JobAttention->save(
						array(
							"job_id"=>$job_id, "attention_id"=>$attention 
						));
				}
			}
			$subject = $this->Prop->getValue('config.mail_title.job_add_finish');
			$subject = str_replace('#company_name_alias#', 
				$company['Company']['company_alias'], $subject);
			$job = $this->Job->find('"Job"."id"=' . $job_id, null, null, 2);
			$contents = $this->getMailTemplate("job_add_finish", $job);
			
			//求人投稿担当者メールアドレス
			$this->MailJob->saveMsg('web@localhost:82', 
				$this->rdCompany->email, $subject, $contents, 
				'x.nan.kuifeng@nssol-sh.com', 'info@localhost:82');
		}
		$this->Session->del('job_info');
		$this->redirect('job/job_add_finish');
	}
	
	function job_add_finish() {
		$this->rdCompany->id=1;
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
	}
	
	function job_list($flg = null) {
		$this->rdCompany->id=1;
		$this->rdCompany->company_id=1;
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		if (!empty($flg)) {
			$this->delCookie("job");
			$this->redirect('job/job_list');
		}
		$company_id = $this->rdCompany->company_id;
		$condition = '"Job"."company_id"=' . $company_id . ' and "Job"."deleted" is null';
		
		$jobs = $this->Job->findAll($condition, null, 'Job.created desc', 
			$this->show, $this->page);
		$count = $this->Job->findCount($condition);
		foreach($jobs as &$job) {
			
			if (date('Y-m-d H:i', time()) >= ($job['Job']['public_start'] . ' ' . $job['Job']['public_start_hour'] . ':' . $job['Job']['public_start_min']) && date(
				'Y-m-d H:i', time()) <= ($job['Job']['public_end'] . ' ' . $job['Job']['public_end_hour'] . ':' . $job['Job']['public_end_min']) && $job['Job']['job_status_id'] == 1 && empty(
				$job['Job']['public_close_date'])) {
				$job['Job']['public_state'] = '掲載中';
			} elseif ((($job['Job']['public_start'] . ' ' . $job['Job']['public_start_hour'] . ':' . $job['Job']['public_start_min']) > date(
				'Y-m-d H:i', time()) || empty($job['Job']['public_start']) || empty(
				$job['Job']['public_end'])) && $job['Job']['job_status_id'] == 1) {
				$job['Job']['public_state'] = '掲載待ち';
			} elseif ($job['Job']['job_status_id'] == 0) {
				$job['Job']['public_state'] = '承認待ち';
			} elseif ($job['Job']['job_status_id'] == 2) {
				$job['Job']['public_state'] = '保留・差し戻し';
			} elseif ($job['Job']['job_status_id'] == 1 && (($job['Job']['public_end'] . ' ' . $job['Job']['public_end_hour'] . ':' . $job['Job']['public_end_min']) < date(
				'Y-m-d H:i', time()) || !empty($job['Job']['public_close_date']))) {
				$job['Job']['public_state'] = '掲載終了';
			}
			$order_count = $this->Order->findCount(
				'"Order"."job_id"=' . $job['Job']['id'] . ' and "Order"."deleted" is null');
			$job['Job']['order_count'] = $order_count;
		}
		$this->setJobCookie($jobs);
		$this->set('jobs', $jobs);
		$this->set('company_id', $company_id);
		$this->setPaging('ajax', '/job/job_list', $count);
	}
	
	function job_detail($job_id) {
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$job = $this->Job->find('Job.id=' . $job_id);
		$this->checkAccess1($job['Job']['company_id'], 
			$this->rdCompany->company_id);
		$job['Job']['post_data'] = $this->processData($job, 'JobPost', 
			'post_id');
		$job['Job']['lang_data'] = $this->processData($job, 'JobHopeLanguage', 
			'hope_language_id');
		$job['Job']['member_data'] = $this->processData($job, 'JobHopeMember', 
			'hope_member_id');
		$job['Job']['attention_data'] = $this->processData($job, 'JobAttention', 
			'attention_id');
		$this->set('job', $job);
	}
	
	function processData($data, $key, $kbn) {
		$arr = array();
		if (empty($data[$key])) {
			return '';
		}
		foreach($data[$key] as $d) {
			$sysdata = $this->SysParams->find(
				'"SysParams"."kbn"=' . '\'' . $kbn . '\'' . ' and "SysParams"."id"=' . $d[$kbn]);
			if ($key == 'JobHopeLanguage' && $d[$kbn] == 4) {
				$arr[] = $data['Job']['hope_language_note'];
			} else {
				$arr[] = $sysdata['SysParams']['name'];
			}
		}
		return implode(',', $arr);
	}
	
	function edit_init() {
		$post_data = $this->SysParams->generateList(
			"\"SysParams\".\"kbn\" = 'post_id' and \"SysParams\".\"deleted\" is null");
		$lang_data = $this->SysParams->generateList(
			"\"SysParams\".\"kbn\" = 'hope_language_id' and \"SysParams\".\"deleted\" is null", 
			'sort');
		$memb_type = $this->SysParams->generateList(
			"\"SysParams\".\"kbn\" = 'hope_member_id' and \"SysParams\".\"deleted\" is null");
		$attention_data = $this->SysParams->generateList(
			"\"SysParams\".\"kbn\" = 'attention_id' and \"SysParams\".\"deleted\" is null");
		
		$this->set('post_data', $post_data);
		$this->set('lang_data', $lang_data);
		$this->set('member_type', $memb_type);
		$this->set('attention_data', $attention_data);
	
	}
	
	function processEdit($data, $key, $kbn) {
		$arr = array();
		if (empty($data[$key])) {
			return $arr;
		}
		foreach($data[$key] as $d) {
			$arr[] = $d[$kbn];
		}
		return $arr;
	}
	
	function job_stop($job_id) {
		$job = $this->Job->find('Job.id=' . $job_id);
		$job['Job']['public_close_date'] = date('Y-m-d H:i:s');
		$this->Job->save($job);
		$this->redirect('/job/job_detail/' . $job['Job']['id']);
	}
	
	function job_republic($job_id) {
		$job = $this->Job->find('"Job"."id"=' . $job_id);
		$this->Job->republic($job['Job']['id']);
		$this->redirect('/job/job_detail/' . $job['Job']['id']);
	}
	
	function job_edit($job_id, $copy_flg = null) {
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$this->edit_init();
		$company = $this->Company->find(
			'"Company"."id"=' . $this->rdCompany->company_id);
		$this->set('company', $company);
		pr($this->data);
		if (empty($this->data)) {
			$job = $this->Job->find('"Job"."id"=' . $job_id);
			$this->checkAccess1($job['Job']['company_id'], 
				$this->rdCompany->company_id);
			if (!empty($job['Job']['email2'])) {
				$job['Job']['email2_flg'] = 1;
			}
			if (!empty($job['Job']['email3'])) {
				$job['Job']['email3_flg'] = 1;
			}
			if (!empty($copy_flg)) {
				$job['Job']['copy_flg'] = $copy_flg;
			}
			$job['Job']['post_type'] = $this->processEdit($job, 'JobPost', 
				'post_id');
			$job['Job']['hope_language'] = $this->processEdit($job, 
				'JobHopeLanguage', 'hope_language_id');
			$job['Job']['hope_member'] = $this->processEdit($job, 
				'JobHopeMember', 'hope_member_id');
			$job['Job']['attention'] = $this->processEdit($job, 'JobAttention', 
				'attention_id');
			$this->data = $job;
		} else {
			$message = $this->Job->valid($this->Valid, $this->data);
			if ($this->data['Job']['email3_flg'] == 1 && empty(
				$this->data['Job']['email3'])) {
				$message .= $this->Valid->TagErrorMsg('required', 'Job/email3');
			}
			if (isset($this->data['Job']['title'])) {
				unset($this->data['Job']['copy_flg']);
				$message .= $this->Valid->ErrorMsg($this->data, 'Job/title', 
					'required');
				$message .= $this->Valid->ErrorMsg($this->data, 'Job/title', 
					'maxlength', '36');
			}
			if (!empty($this->data['Job']['hope_language'])) {
				foreach($this->data['Job']['hope_language'] as $index => $hope) {
					if ($this->data['Job']['hope_language'][$index] == 4 && empty(
						$this->data['Job']['hope_language_note'])) {
						$message .= $this->Valid->TagErrorMsg('required', 
							'Job/hope_language_note');
					}
				}
			}
			if ($message) {
				$this->set('message', $message);
				$this->render('job_edit');
				exit();
			}
			$this->Session->write('job_info', $this->data);
			$this->redirect('job/job_edit_confirm');
		}
	}
	
	function processConfirm($data, $key, $kbn) {
		$arr = array();
		if (empty($data['Job'][$key])) {
			return null;
		}
		foreach($data['Job'][$key] as $d) {
			$sysdata = $this->SysParams->find(
				'"SysParams"."kbn"=' . '\'' . $kbn . '\'' . ' and "SysParams"."id"=' . $d);
			if ($key == 'hope_language' && $d == 4) {
				$arr[] = $data['Job']['hope_language_note'];
			} else {
				$arr[] = $sysdata['SysParams']['name'];
			}
		}
		return implode(',', $arr);
	}
	
	function job_edit_confirm() {
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$job = $this->Session->read('job_info');
		$company = $this->Company->find(
			'"Company"."id"=' . $this->rdCompany->company_id);
		$this->set('company', $company);
		
		$job['Job']['email1'] = $company['Company']['email'];
		if ($job['Job']['email2_flg'] == 1) {
			$job['Job']['email2'] = $company['Company']['incept_email'];
		}
		$job['Job']['post_data'] = $this->processConfirm($job, 'post_type', 
			'post_id');
		$job['Job']['lang_data'] = $this->processConfirm($job, 'hope_language', 
			'hope_language_id');
		$job['Job']['member_data'] = $this->processConfirm($job, 'hope_member', 
			'hope_member_id');
		$job['Job']['attention_data'] = $this->processConfirm($job, 'attention', 
			'attention_id');
		$this->set('job', $job);
	}
	
	function job_edit_save() {
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$job_info = $this->Session->read('job_info');
		$company = $this->Company->find(
			'"Company"."id"=' . $this->rdCompany->company_id);
		$job_info['Job']['email1'] = $company['Company']['email'];
		if ($job_info['Job']['email2_flg'] == 1) {
			$job_info['Job']['email2'] = $company['Company']['incept_email'];
		} else {
			$this->Job->delFieldById($job_info['Job']['id'], 'email2');
		}
		if ($job_info['Job']['email3_flg'] != 1) {
			$job_info['Job']['email3'] = null;
			$this->Job->delFieldById($job_info['Job']['id'], 'email3');
		}
		if (!empty($job_info['Job']['copy_flg'])) {
			$job_info['Job']['id'] = null;
			$job_info['Job']['job_status_id'] = 0;
			$job_info['Job']['title'] = null;
		}
		$job_info['Job']['admin_id'] = $this->rdCompany->id;
		if ($this->Job->save($job_info)) {
			if (empty($job_info['Job']['copy_flg'])) {
				$job_id = $job_info['Job']['id'];
				$this->JobPost->delByJobid($job_id);
				$this->JobHopeMember->delByJobid($job_id);
				$this->JobHopeLanguage->delByJobid($job_id);
				$this->JobAttention->delByJobid($job_id);
			} else {
				$job_id = $this->Job->getLastInsertID();
			
		//add yangjie 090721
			//				$subject=$this->Prop->getValue('config.mail_title.job_add_finish');
			//				$subject=str_replace('#company_name_alias#',$company['Company']['company_alias'], $subject);		
			//	            $job=$this->Job->find('Job.id='.$job_id,null,null,2);
			//				$contents=$this->getMailTemplate("job_add_finish",$job);
			//				
			//				//求人投稿担当者メールアドレス
			//				$this->MailJob->saveMsg('web@localhost:82',$this->rdCompany->email,$subject,$contents,'recruit@localhost:82','info@localhost:82');		
			}
			foreach($job_info['Job']['post_type'] as $post_type) {
				$this->JobPost->save(
					array(
						"job_id"=>$job_id, "post_id"=>$post_type 
					));
			}
			if (!empty($job_info['Job']['hope_member'])) {
				foreach($job_info['Job']['hope_member'] as $hope_member) {
					$this->JobHopeMember->save(
						array(
							"job_id"=>$job_id, 
							"hope_member_id"=>$hope_member 
						));
				}
			}
			if (!empty($job_info['Job']['hope_language'])) {
				foreach($job_info['Job']['hope_language'] as $hope_language) {
					$this->JobHopeLanguage->save(
						array(
							"job_id"=>$job_id, 
							"hope_language_id"=>$hope_language 
						));
				}
			}
			if (!empty($job_info['Job']['attention'])) {
				foreach($job_info['Job']['attention'] as $attention) {
					$this->JobAttention->save(
						array(
							"job_id"=>$job_id, "attention_id"=>$attention 
						));
				}
			}
		}
		
		if ($job_info['Job']['copy_flg'] == 1) {
			$subject = $this->Prop->getValue('config.mail_title.job_add_finish');
			$subject = str_replace('#company_name_alias#', 
				$company['Company']['company_alias'], $subject);
			$job = $this->Job->find('Job.id=' . $job_id, null, null, 2);
			$contents = $this->getMailTemplate("job_add_finish", $job);
			
			//求人投稿担当者メールアドレス
			$this->MailJob->saveMsg('web@localhost:82', 
				$this->rdCompany->email, $subject, $contents, 
				'x.nan.kuifeng@nssol-sh.com', 'info@localhost:82');
		}
		
		$this->Session->del('job_info');
		$this->redirect('job/job_add_finish');
	}
	
	function job_delete() {
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$delcs = $_COOKIE['job'];
		$this->Job->deleteJob($delcs);
		$this->delCookie("job");
		$this->redirect('job/job_list');
	}
	
	function job_close_public() {
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$delcs = $_COOKIE['job'];
		$this->Job->closeJob($delcs);
		$this->delCookie("job");
		$this->redirect('job/job_list');
	}
	
	function excel_download($company_id) {
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$this->checkAccess1($company_id, $this->rdCompany->company_id);
		//$delcs=$_COOKIE['job'];
		//$condition='Job.deleted is null and Job.id in ('.$delcs.')';
		$condition = '"Job"."deleted" is null and "Job"."company_id"=' . $company_id;
		$order = 'Job.created desc';
		$data = $this->Job->findAll($condition, null, $order, null, null, 2);
		$this->Job->processExcelData($data);
		$file_name = "job_data_" . date("YmdHis");
		$col_name = $this->Job->getExcelCol();
		$this->Excel->createExcel($file_name, $col_name, $data);
		exit();
	
		//		$this->delCookie("job");
	//		$this->redirect('job/job_list');
	}
	
	function job_copy($job_id) {
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$this->redirect('/job/job_edit/' . $job_id . '/1');
	}
	
	function order_list($job_id) {
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$job = $this->Job->find('"Job"."id"=' . $job_id);
		$this->checkAccess1($job['Job']['company_id'], 
			$this->rdCompany->company_id);
		$condition = 'Order.job_id=' . $job_id;
		
		$all_orders = $this->Order->findAll($condition, null, 
			'Order.created desc', $this->show, $this->page);
		$count = $this->Order->findCount($condition);
		foreach($all_orders as &$order) {
			$member = $this->Member->find(
				'"Member"."id"=' . $order['Order']['member_id']);
			
			$order['Order']['member_id'] = $member['Member']['id'];
			$order['Order']['member_name'] = $member['Member']['name_kanji'];
			$order['Order']['nationality'] = $member['SysParams1']['name'];
			$order['Order']['address'] = $member['SysParams5']['name'] . '，' . $member['SysParams3']['name'];
			
			$work_type = $member['SysParams9']['name'];
			$work_type .= '，' . $member['SysParams10']['name'];
			$work_type .= '，' . $member['SysParams11']['name'];
			$order['Order']['interest_work_type'] = $work_type;
			$order['Order']['status'] = $member['SysParams12']['name'];
			
			$order['Order']['member_email'] = $member['Member']['email'];
		}
		$this->set('job_id', $job_id);
		$this->set('all_orders', $all_orders);
		$this->set('page', $this->page);
		$this->setPaging('ajax', '/job/order_list/' . $job_id, $count);
	}
	
	function order_excel_download($job_id) {
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$job = $this->Job->find('"Job"."id"=' . $job_id);
		$this->checkAccess1($job['Job']['company_id'], 
			$this->rdCompany->company_id);
		$condition = '"Order"."job_id"=' . $job_id . ' and "Order"."deleted" is null';
		$order = 'Order.created desc';
		$data = $this->Order->findAll($condition, null, $order, null, null, 2);
		$this->processExcelData($data);
		$file_name = "order_data_" . date("YmdHis");
		$col_name = $this->Order->getExcelCol();
		$this->Excel->createExcel($file_name, $col_name, $data);
		exit();
	}
	
	function processExcelData(&$data) {
		foreach($data as &$d) {
			$member = $this->Member->find(
				'"Member"."id"=' . $d['Order']['member_id']);
			$d['Order']['sex'] = $member['SysParams4']['name'];
			$d['Order']['nationality'] = $member['SysParams1']['name'];
			$d['Order']['nation_address'] = $member['SysParams5']['name'];
			$d['Order']['city_address'] = $member['SysParams3']['name'];
			$d['Order']['other_address'] = $member['Member']['address_location_other'];
			$d['Order']['work_type1'] = $member['SysParams6']['name'];
			$d['Order']['work_type2'] = $member['SysParams7']['name'];
			$d['Order']['work_type3'] = $member['SysParams8']['name'];
			$d['Order']['interest_work_type1'] = $member['SysParams9']['name'];
			$d['Order']['interest_work_type2'] = $member['SysParams10']['name'];
			$d['Order']['interest_work_type3'] = $member['SysParams11']['name'];
			$d['Order']['education'] = $member['SysParams13']['name'];
			$d['Order']['status'] = $member['SysParams12']['name'];
			$d['Order']['note'] = $member['Member']['note'];
			$d['Order']['member_email'] = $member['Member']['email'];
			$d['Order']['member_grad_date'] = $member['Member']['grad_date'];
			$d['Order']['name_kanji'] = $member['Member']['name_kanji'];
			$d['Order']['name_kana'] = $member['Member']['name_kana'];
			$language = '';
			if (!empty($member['Member']['language_jp_id'])) {
				$language .= '日语：' . $member['SysParams14']['name'] . '(' . $member['Member']['language_jp_note'] . ');';
			}
			if (!empty($member['Member']['language_en_id'])) {
				$language .= '英语：' . $member['SysParams16']['name'] . '(' . $member['Member']['language_en_note'] . ');';
			}
			if (!empty($member['Member']['language_ch_bj_id'])) {
				$language .= '普通语：' . $member['SysParams18']['name'] . '(' . $member['Member']['language_ch_bj_note'] . ');';
			}
			if (!empty($member['Member']['language_other_id1'])) {
				$language .= $member['Member']['language_other_note1'] . '：' . $member['SysParams17']['name'] . ';';
			}
			if (!empty($member['Member']['language_other_id2'])) {
				$language .= $member['Member']['language_other_note2'] . '：' . $member['SysParams19']['name'] . ';';
			}
			
			$d['Order']['language'] = $language;
		}
	}
	
	/**
	 * 2.5.1共通_応募管理へ遷移するとき呼び出す
	 * 
	 * create: 現存
	 * update: 2012-03-03 ツバサ（エスワイシステム）
	 * */
	function order_detail($order_id, $page = 1) {
		if (empty($this->rdCompany->id)) {
			$this->redirect("/company/index/Job/order_detail/$order_id/$page");
			exit();
		}
		//@author wangyuhua 2012/4/3 start 下载履历参数加密
		$param1 = $order_id."/1";
		$param2 = $order_id."/2";
		$param3 = $order_id."/3";
		$downfile1 = $this->Order->encodeParam($param1);
		$downfile2 = $this->Order->encodeParam($param2);
		$downfile3 = $this->Order->encodeParam($param3);
		//@author wangyuhua 2012/4/3 end
		$order = $this->Order->find('"Order"."deleted" is null and "Order"."id" ='.$order_id);
		$member_id = $order['Order']['member_id'];
		$this->checkAccess1($order['Order']['company_id'], $this->rdCompany->company_id);
		$member = $this->Member->find("\"Member\".id=" . $member_id . " and \"Member\".deleted is null");
		$member['Member']['public_profile'] = $this->setPublicProfileFlg($member['Member']['public_profile_flg']);
		$member['Member']['visa'] = $this->setWorkVisa($member);
		$resumeData = $this->getResumeData($member_id);
		$this->setIncome($member['Member']['hope_income'], $member['Member']['hope_income_cur'],$member['Member']['hope_income_to'],'hope_income');
		$this->memberExpToArray($member);
		$this->set("resumeData", $resumeData);
// 		$this->set("expworktype", $resumeData['expworktype']);
// 		$this->set("resume", $resumeData['resume']);
// 		$this->set("edu", $resumeData['edu']);
// 		$this->set("work", $resumeData['work']);
		$this->set("member", $member);
		$this->set('order', $order);
		//@author wangyuhua 2012/4/3 start 下载履历参数
		$this->set("downfile1", $downfile1);
		$this->set('downfile2',$downfile2);
		$this->set('downfile3',$downfile3);
		//@author wangyuhua 2012/4/3 end
	}
	
	function setJobCookie(& $data) {
		$delete = array();
		if (isset($_COOKIE['job']))
			$delete = split(',', $_COOKIE['job']);
		foreach($data as & $d) {
			$id = $d['Job']['id'];
			if (in_array($id, $delete)) {
				$d['Job']['delete'] = $id;
			}
		}
	}
	
	//@author wangyuhua 2012/4/3 update start 下载履历参数解密，修改了方法参数
	function member_info_download($param){
		$params = $this->Order->decodeParam($param);
		$arr = split("/",$params);
		$order_id = $arr[0];
		$flg = $arr[1];
		//@author wangyuhua 2012/4/3 update end 下载履历参数解密
		
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$order = $this->Order->find('"Order"."id"=' . $order_id);
		$this->checkAccess1($order['Order']['company_id'], 
			$this->rdCompany->company_id);
		$job_id = $order['Order']['job_id'];
		$member_id = $order['Order']['member_id'];
		$path = null;
		if ($flg == 1) {
			$file_name = $order['Order']['file_name'];
		} elseif ($flg == 2) {
			$file_name = $order['Order']['file_name_2'];
		} else {
			$file_name = $order['Order']['file_name_3'];
		}
		if (!empty($file_name)) {
			$path = $this->Prop->getValue('config.file.resume.dir') . DS . floor(
				$job_id / 1000) . DS . $job_id . DS . floor($member_id / 1000) . DS . $member_id;
		} else {
			exit();
		}
		$this->FileEncrtypt->downloadFile($path, $file_name, $flg);
		exit();
	}
	/**
	 * @author zhouguoyan
	 * @desc News的详细页面,$id是News表里的id
	 **/
	function news_detail($id) {
		if (empty($this->rdCompany->id)) {
			$this->redirect('/company/index');
		}
		$condition = '"News"."id"=' . $id . ' and "News"."deleted" is null';
		$this->data = $this->News->find($condition);
	}
}
?>
